<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('人员信息列表')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>

    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="deptId" name="deptId">
                        <input type="hidden" id="parentId" name="parentId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>姓名：</label>
                                    <input type="text" name="name"/>
                                </li>
                                <li>
                                    <label>证件号：</label>
                                    <input type="text" name="idNo"/>
                                </li>
                                <li>
                                    <label>卡号：</label>
                                    <input type="text" name="cardNo"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="door:user:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="door:user:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="door:user:import">
                        <i class="fa fa-upload"></i> 导入
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="door:user:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                    <a id="blacklist" class="btn btn-default disabled" data-toggle="modal" data-target="#myModal2" shiro:hasPermission="door:user:blacklist">
                        <i class="fa fa-user-times"></i> 拉黑
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">解禁日期</h4>
                </div>

                <div class="modal-body">
                    <div class="form-group">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input type="text" class="form-control" id="liftTime" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label">备注：</label>
                        <textarea class="form-control" type="text" id="remark"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="blacklist()">保存</button>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('door:user:edit')}]];
        var removeFlag = [[${@permission.hasPermi('door:user:remove')}]];
        var yesNo = [[${@dict.getType('snk_yes_no')}]];
        var prefix = ctx + "door/user";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryUserList();
            queryDeptTree();
        });

        function queryUserList() {
            var options = {
                uniqueId: "id",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                blacklistUrl: prefix + "/blacklist",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                clickToSelect: true,
                modalName: "人员信息",
                columns: [{
                    field: 'state',
                    checkbox: true
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'userNo',
                    title: '人员编号'
                },
                {
                    field: 'cardNo',
                    title: '凭证',
                    formatter: function(value, row, index) {
                        var html = "<i class='fa fa fa-vcard' title='卡号'></i>" + ($.common.isEmpty(row.cardNo) ? "" : row.cardNo);
                        if (!$.common.isEmpty(row.photo)) {
                            html += "<br/>" + $.common.sprintf("<img class='img-circle img-xs' data-height='%s' data-width='%s' data-target='%s' src='%s' title='头像'/>", 'auto', 'auto', 'self', ctx + row.photo.substr(1));
                        }
                        html += "<br/><i class='fa fa-hand-pointer-o' title='指纹'></i>" + ($.common.isEmpty(row.fingerNum) ? "0" : JSON.parse(row.fingerNum).length);
                        return html;
                    }
                },
                {
                    field: 'deptName',
                    title: '部门'
                },
                {
                    field: 'postName',
                    title: '岗位'
                },
                {
                    field: 'idNo',
                    title: '证件号'
                },
                {
                    field: 'phone',
                    title: '手机'
                },
                {
                    field: 'email',
                    title: '邮箱'
                },
                {
                    field: 'address',
                    title: '地址'
                },
                {
                    field: 'blacklist',
                    title: '黑名单',
                    formatter: function(value, row, index) {
                        var dictLabel = $.table.selectDictLabel(yesNo, value);
                        if (value == 1) {
                            return "<span style='color: red;'>" + dictLabel + "</span>";
                        }
                        return dictLabel;
                    }
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            $('#bootstrap-table').on('check.bs.table', function () {
                disabledBtn();
            });
            $('#bootstrap-table').on('uncheck.bs.table', function () {
                disabledBtn();
            });
            $('#bootstrap-table').on('check-all.bs.table', function () {
                disabledBtn();
            });
            $('#bootstrap-table').on('uncheck-all.bs.table', function () {
                $("#blacklist").addClass("disabled", "disabled");
            });
        }

        function disabledBtn() {
            var rows = $("#bootstrap-table").bootstrapTable("getSelections");
            var disabled = false;
            $.each(rows, function (index, obj) {
                if (obj.blacklist == 1) {   // 包含黑名单不显示拉黑按钮
                    disabled = true;
                    return;
                }
            });
            if (rows.length == 0 || disabled) {
                $("#blacklist").addClass("disabled", "disabled");
            } else {
                $("#blacklist").removeClass("disabled");
            }
        }

        function queryDeptTree()
        {
            var url = ctx + "system/dept/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#deptId").val(treeNode.id);
                $("#parentId").val(treeNode.pId);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryDeptTree();
        });

        /* 用户管理-部门 */
        function dept() {
            var url = ctx + "system/dept";
            $.modal.openTab("部门管理", url);
        }

        $("#liftTime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            startDate: new Date(),
            autoclose: true
        });

        function blacklist() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要拉黑选中的" + rows.length + "条数据吗?", function() {
                var url = table.options.blacklistUrl;
                var data = { "ids": rows.join(), "liftTime": document.getElementById("liftTime").value, "remark": document.getElementById("remark").value};
                $.operate.submit(url, "post", "json", data);
                $("#blacklist").addClass("disabled", "disabled");
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>